/* ***********************
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is SiteAuthors.js module.
 *
 * The Initial Developer of the Original Code is Rob Gerns.
 *
 * Portions created by the Initial Developer are Copyright (C) 2010
 * the Initial Developer. All Rights Reserved.
 *
 **************************/

/*************************************************
* Function Name(s): SiteAuthors; writeAuthors
*
* Purpose:
* Check to see if there are any authors defined in the 
* 'brief' section of the Oister file.  If so, for each
* author create the necessary div and write the author  
* inside the div.
**************************************************/

function siteAuthors(oisterFile){	
	
 //Check to see if author's name was included
 var checkSiteAuthors="";

 if(oisterFile.getElementsByTagName("authors")!=undefined){
	checkSiteAuthors = oisterFile.getElementsByTagName("authors").length;
 }
             
 if(checkSiteAuthors!=undefined && checkSiteAuthors!="" && checkSiteAuthors > 0 ){
         
  //Loop around to make sure that all of the authorsName elements are read
	for(var i = 0; i < checkSiteAuthors; i++){
	     
   /* the current child of the "authors" element, which could be an "authorName" or 
    * an "authorEmail" node */
	 var authorsNode = oisterFile.getElementsByTagName("authors")[0].childNodes[i+1]; 
		  
	 //only call the writeAuthors function if the node is in fact an "authorsName" node 
   if(authorsNode.nodeName == "authorName"){
	     
    for(var j = 0; j < checkSiteAuthors; j++){
		 
		 var authors = authorsNode.firstChild.nodeValue;
          
		 //Call the writeAuthors function to create the appropriate div
		 writeAuthors(authors,j);
		
    }

   }	

  }	

 }
  
} 

var divAuthors; //Used to create a node in the DOM to contain the site author(s) info
var authorsId;  //Used to give the node an ID

function writeAuthors(authorsData,authorsNum){

 //if the authors names aren't blank or undefined, create the div and write in the info
 if(authorsData != undefined && authorsData != "") {
  
  divAuthors = document.createElement("div");
	document.getElementById('begin').appendChild(divAuthors);
  authorsId = divAuthors.id = "authors"+authorsNum;
  document.getElementById(authorsId).className = "authors";
  document.getElementById(authorsId).innerHTML = authorsData;

 }

}